<?php
	include_once("parser.php");

	class PostContainer {
		//Index of current post
		private $currIter = 0;
		//Array of posts
		public $posts = null;
		//Array of associated parsers
		public $parsers = null;
		public $status = null;
		public $color = "ffffff";
		
		//modify if necessary
		function __construct() {
			$this->posts = array();
			$this->parsers = array();
		}
		
		function populatePosts() {
			foreach ($this->parsers as $parser) {
				if($parser->status)
					$this->posts = array_merge($this->posts, $parser->scrapePosts());
			}
			//shuffle for now as everything has equal weight
			shuffle($this->posts);
			
		}
		
		function addParser ($parser) {
			array_push($this->parsers, $parser);
		}
		
		function removeParser ($index) {
			unset($this->parsers[$index]);
		}
		
		function setParserStatus ($index, $enabled) {
			$this->parsers[$index]->status = $enabled;
		}
		
		function getNextPost() {
			if($this->currIter >= count($this->posts))
				return null;
			$post = $this->posts[$this->currIter];
			$this->currIter++;
			return $post;
		}
		
		function resetPosts() {
			$this->currIter = 0;
		}
		
		function addParsersByArray($arr) {
			for($i=0; $i<count($arr); $i++) {
				$en = intval(substr($arr[$i], strlen($arr[$i])-1));
				$name = substr($arr[$i], 0, strlen($arr[$i])-2);
				if(strpos($name, "Reddit")!==false) {
					if(strpos($name, "RedditFront")!==false) {
						$this->addParser(new RedditParser(""));
					}
					else {
						$sub = strtolower(substr($name,6));
						$this->addParser(new RedditParser($sub));
					}
				}
				else if(strpos($name, "4chan")!==false) {
					$this->addParser(new forchanParser(""));
				}
				else if(strpos($name, "Gmail")!==false) {
					$this->addParser(new gmailParser("superscraperdummytester1001@gmail.com","ss#1ss#1"));
				}
				else {
					$this->addParser(new DummyParser());
				}
				if($en == 0) {
					$this->parsers[count($this->parsers)-1]->status = false;
				}
			}
			
		}
	}
	

?>